import Dialog from "@vant/weapp/dialog/dialog";

Component({
    options: {
        addGlobalClass: true
    },
    properties: {
        formInfo: {
            type: Object,
            value: {}
        },
        formItemList: {
            type: Array,
            value: []
        },
        imageList: {
            type: Array,
            value: []
        }
    },
    data: {
        info: {},
        formList: [],
        selfImageList: []
    },
    observers: {
        'formInfo': function (formInfo) {
            this.setData({info: formInfo})
        },
        'formItemList': function (formItemList) {
            this.setData({formList: formItemList})
        },
        'imageList': function (imageList) {
            this.setData({selfImageList: imageList})
        }
    },
    ready() {
        this.setData({
            formList: this.data.formItemList,
            info: this.data.formInfo,
            selfImageList: this.data.imageList
        })
    },
    methods: {
        onAfterRead(e) {
            this.triggerEvent('afterRead', e);
        },
        onOversize() {
            Dialog.alert({ title: '提示', message: '文件大小不能超过 2MB' });
        },
        onDeleteImage() {
            this.triggerEvent('deleteImage');
        },
        onChangeField(e) {
            this.triggerEvent('changeField', e);
        },
        onChangePicker(e) {
            this.triggerEvent('changePicker', e);
        },
        onStepperChange(e) {
            this.triggerEvent('stepperChange', e);
        },
        onSaveForm() {
            this.triggerEvent('saveForm');
        }
    }
});
